package cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.impl;

import cn.tedu.hospitalgroupproject.server.common.pojo.vo.PageData;
import cn.tedu.hospitalgroupproject.server.common.util.PageInfoToPageDataConverter;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.mapper.DoctorTitleAppLimitMapper;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.IDoctorTitleAppLimitRepository;
import cn.tedu.hospitalgroupproject.server.content.pojo.entity.DoctorTitleAppLimit;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DoctorTitleAppLimitListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DoctorTitleAppLimitStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class DoctorTitleAppLimitRepositoryImpl implements IDoctorTitleAppLimitRepository {

   @Autowired
   private DoctorTitleAppLimitMapper doctorTitleAppLimitMapper;

    public DoctorTitleAppLimitRepositoryImpl() {
        log.info("创建数据库对象:DoctorTitleAppLimitRepositoryImpl");
    }

    @Override
    public int insert(DoctorTitleAppLimit doctorTitleAppLimit) {
        log.debug("开始向[医生级别预约上限表]中插入数据:{}",doctorTitleAppLimit);
        return doctorTitleAppLimitMapper.insert(doctorTitleAppLimit);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始[删除指定职称ID下的职称数据],职称ID:{}",id);
        return doctorTitleAppLimitMapper.deleteById(id);
    }

    @Override
    public int updateById(DoctorTitleAppLimit doctorTitleAppLimit) {
        log.debug("开始[更新指定职称ID下的职称数据],:{}",doctorTitleAppLimit);
        return doctorTitleAppLimitMapper.updateById(doctorTitleAppLimit);
    }

    @Override
    public DoctorTitleAppLimitStandardVO getStandardById(Long id) {
        log.debug("开始执行[根据指定职称ID查询对应数据]:{}",id);
        return doctorTitleAppLimitMapper.getStandardById(id);
    }

    @Override
    public DoctorTitleAppLimitStandardVO selectByTitleName(String doctorTitle) {
        log.debug("开始[根据职称查找数据]:{}",doctorTitle);
        return doctorTitleAppLimitMapper.selectByName(doctorTitle);
    }

    @Override
    public PageData<DoctorTitleAppLimitListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询医生职称预约挂号上限列表】，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<DoctorTitleAppLimitListVO> list = doctorTitleAppLimitMapper.listDoctorTitleAppLimit();
        PageInfo<DoctorTitleAppLimitListVO> pageInfo = new PageInfo<>(list);
        PageData<DoctorTitleAppLimitListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
